/**
 * com.chaeron.GPS - An API for access to GPS devices.
 *
 *
 * Copyright (c) 2001, 2002 Chaeron Corporation,
 * All rights reserved.
 * 
 * Chaeron grants you a non-exclusive license to use, modify and re-distribute
 * this program under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version, provided that this copyright notice and 
 * license appear on all copies of the software.
 * 
 * Software is provided "AS IS," without a warranty of any kind. ALL EXPRESS OR
 * IMPLIED REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE
 * HEREBY EXCLUDED. THE ENTIRE RISK ARISING OUT OF USING THE SOFTWARE IS ASSUMED
 * BY THE LICENSEE. See the GNU General Public License for more details.
 *
 * CHAERON AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY
 * LICENSEE OR ANY THIRD PARTY AS A RESULT OF USING OR DISTRIBUTING SOFTWARE.
 * IN NO EVENT WILL CHAERON OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE,
 * PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL
 * OR PUNITIVE DAMAGES, HOWEVER CAUSED AN REGARDLESS OF THE THEORY OF LIABILITY,
 * ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF CHAERON HAS
 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

 * @version     1.02
 * @author      Andrzej Jan Taramina, Chaeron Corporation
 *              andrzej@chaeron.com
 */

package com.chaeron.GPS.event.decorator;

//***************************************************************************
//*
//*     Imports
//*
//***************************************************************************/

import com.chaeron.GPS.*;
import com.chaeron.GPS.event.*;


//***************************************************************************
//*
//*    GPSWaypointDecorator Class definition
//*
//***************************************************************************/

/**
 * The GPSWaypointDecorator provides added functions to the GPSWaypoint Event Value
 *
 */
 
public class GPSWaypointDecorator extends GPSEventDecorator implements GPSWaypoint
{

	//***************************************************************************
	//*
	//*     Constant definitions
	//*
	//***************************************************************************/
	
	//***************************************************************************
	//*
	//*     Attributes
	//*
	//***************************************************************************/
	
	private	GPSWaypoint			delegate	= null;
	

	//***************************************************************************
	//*
	//*     Constructor
	//*
	//***************************************************************************/
	
	/**
	 * Create a GPSWaypointDecorator
	 *
	 * @param	waypoint	GPSWaypoint to delegate method calls to
	 */
	
	public GPSWaypointDecorator( GPSWaypoint waypoint )
	{
		super();
		
		delegate = waypoint;
	}
	
	//***************************************************************************
	//*
	//*     Output Methods (required by abstract base class)
	//*
	//***************************************************************************/
	
	void toXMLImpl( boolean namespace )
	{
		if( Compile.INCLUDE_EVENT_TOXML ) {
			writeString( genXMLStartTag( GPSXMLTag.XML_TAG_WAYPOINT, namespace ) );	
			
			writeString( genXMLStartTag( GPSXMLTag.XML_TAG_POSITION, false ) );  
			
			if( isMethodImplemented( WAYPOINT_METHOD_LATITUDE ) ) {
				writeString( genXMLValueTag( GPSXMLTag.XML_TAG_LATITUDE, String.valueOf( delegate.getLatitude() ) ) );
			}
			
			if( isMethodImplemented( WAYPOINT_METHOD_LONGITUDE ) ) {
				writeString( genXMLValueTag( GPSXMLTag.XML_TAG_LONGITUDE, String.valueOf( delegate.getLongitude() ) ) );
			}
			
			if( isMethodImplemented( WAYPOINT_METHOD_ALTITUDE ) ) {
				writeString( genXMLValueTag( GPSXMLTag.XML_TAG_ALTITUDE, String.valueOf( delegate.getAltitude() ) ) );
			}
			
			if( isMethodImplemented( WAYPOINT_METHOD_DEPTH ) ) {
				writeString( genXMLValueTag( GPSXMLTag.XML_TAG_DEPTH, String.valueOf( delegate.getDepth() ) ) );
			}
			
			if( isMethodImplemented( WAYPOINT_METHOD_DISTANCE ) ) {
				writeString( genXMLValueTag( GPSXMLTag.XML_TAG_DISTANCE, String.valueOf( delegate.getDistance() ) ) );
			}
			
			writeString( genXMLEndTag( GPSXMLTag.XML_TAG_POSITION ) );
			
			if( isMethodImplemented( WAYPOINT_METHOD_IDENTIFICATION | 
									 WAYPOINT_METHOD_TYPE | 
									 WAYPOINT_METHOD_SUBCLASS | 
									 WAYPOINT_METHOD_ATTRIBUTES |
									 WAYPOINT_METHOD_COMMENT ) ) {
				
				writeString( genXMLStartTag( GPSXMLTag.XML_TAG_IDENTIFICATION, false ) );  
				
				if( isMethodImplemented( WAYPOINT_METHOD_IDENTIFICATION ) ) {
					writeString( genXMLValueTag( GPSXMLTag.XML_TAG_IDENTIFIER, delegate.getIdentification() ) );
				}
				
				if( isMethodImplemented( WAYPOINT_METHOD_TYPE ) ) {
					writeString( genXMLValueTag( GPSXMLTag.XML_TAG_TYPE, String.valueOf( delegate.getType() ) ) );
				}
				
				if( isMethodImplemented( WAYPOINT_METHOD_SUBCLASS ) ) {
					writeString( genXMLValueTag( GPSXMLTag.XML_TAG_SUBCLASS, toHexString( delegate.getSubclass() ) ) );
				}
				
				if( isMethodImplemented( WAYPOINT_METHOD_ATTRIBUTES ) ) {
					writeString( genXMLValueTag( GPSXMLTag.XML_TAG_ATTRIBUTES, String.valueOf( delegate.getAttributes() ) ) );
				}
				
				if( isMethodImplemented( WAYPOINT_METHOD_COMMENT ) && delegate.getComment().length() > 0 ) {
					writeString( genXMLValueTag( GPSXMLTag.XML_TAG_COMMENT, delegate.getComment() ) );
				}
				
				
				writeString( genXMLEndTag( GPSXMLTag.XML_TAG_IDENTIFICATION ) );
			}
			
			if( isMethodImplemented( WAYPOINT_METHOD_ESTIMATEDTIMEENROUTE ) ) {
				
				writeString( genXMLStartTag( GPSXMLTag.XML_TAG_TIME, false ) ); 
				
				if( isMethodImplemented( WAYPOINT_METHOD_ESTIMATEDTIMEENROUTE ) ) {
					writeString( genXMLValueTag( GPSXMLTag.XML_TAG_ESTIMATEDTIMEENROUTE, String.valueOf( delegate.getEstimatedTimeEnroute() ) ) );
				}
				
				writeString( genXMLEndTag( GPSXMLTag.XML_TAG_TIME ) );
			}

			if( isMethodImplemented( WAYPOINT_METHOD_COLOUR |
									 WAYPOINT_METHOD_DISPLAYOPTIONS |
									 WAYPOINT_METHOD_SYMBOLTYPE ) ) {
				
				writeString( genXMLStartTag( GPSXMLTag.XML_TAG_DISPLAY, false ) ); 
				
				if( isMethodImplemented( WAYPOINT_METHOD_COLOUR	) ) {
					writeString( genXMLValueTag( GPSXMLTag.XML_TAG_COLOUR, String.valueOf( delegate.getColour() ) ) );
				}
				
				if( isMethodImplemented( WAYPOINT_METHOD_DISPLAYOPTIONS ) ) {
					writeString( genXMLValueTag( GPSXMLTag.XML_TAG_DISPLAYOPTIONS, String.valueOf( delegate.getDisplayOptions() ) ) );
				}
				
				if( isMethodImplemented( WAYPOINT_METHOD_SYMBOLTYPE ) ) {
					writeString( genXMLValueTag( GPSXMLTag.XML_TAG_SYMBOLID, String.valueOf( delegate.getSymbolType() ) ) );
				}
				
				writeString( genXMLEndTag( GPSXMLTag.XML_TAG_DISPLAY ) );
			}
			
			if( ( isMethodImplemented( WAYPOINT_METHOD_ADDRESS ) 	 && delegate.getAddress().length() > 0 ) |
				( isMethodImplemented( WAYPOINT_METHOD_CITY ) 		 && delegate.getCity().length() > 0 ) |
				( isMethodImplemented( WAYPOINT_METHOD_STATECODE ) 	 && delegate.getStateCode().length() > 0 ) |
				( isMethodImplemented( WAYPOINT_METHOD_COUNTRYCODE ) && delegate.getCountryCode().length() > 0 ) |
				( isMethodImplemented( WAYPOINT_METHOD_FACILITY ) 	 && delegate.getFacility().length() > 0 ) |
				( isMethodImplemented( WAYPOINT_METHOD_CROSSROAD ) 	 && delegate.getCrossroad().length() > 0 ) ) {
				
				writeString( genXMLStartTag( GPSXMLTag.XML_TAG_LOCATION, false ) ); 
				
				if( isMethodImplemented( WAYPOINT_METHOD_ADDRESS ) ) {
					writeString( genXMLValueTag( GPSXMLTag.XML_TAG_ADDRESS, delegate.getAddress() ) );
				}
				
				if( isMethodImplemented( WAYPOINT_METHOD_CITY ) ) {
					writeString( genXMLValueTag( GPSXMLTag.XML_TAG_CITY, delegate.getCity() ) );
				}
				
				if( isMethodImplemented( WAYPOINT_METHOD_STATECODE ) ) {
					writeString( genXMLValueTag( GPSXMLTag.XML_TAG_STATECODE, delegate.getStateCode() ) );
				}
				
				if( isMethodImplemented( WAYPOINT_METHOD_COUNTRYCODE ) ) {
					writeString( genXMLValueTag( GPSXMLTag.XML_TAG_COUNTRYCODE, delegate.getCountryCode() ) );
				}
				
				if( isMethodImplemented( WAYPOINT_METHOD_FACILITY ) ) {
					writeString( genXMLValueTag( GPSXMLTag.XML_TAG_FACILITY, delegate.getFacility() ) );
				}
				
				if( isMethodImplemented( WAYPOINT_METHOD_CROSSROAD ) ) {
					writeString( genXMLValueTag( GPSXMLTag.XML_TAG_CROSSROAD, delegate.getCrossroad() ) );
				}
				
				writeString( genXMLEndTag( GPSXMLTag.XML_TAG_LOCATION ) );
			}
				

			if( isMethodImplemented( WAYPOINT_METHOD_LINKIDENTIFICATION ) ) {
			
				writeString( genXMLStartTag( GPSXMLTag.XML_TAG_OTHER, false ) ); 
				
				if( isMethodImplemented( WAYPOINT_METHOD_LINKIDENTIFICATION ) ) {
					writeString( genXMLValueTag( GPSXMLTag.XML_TAG_LINKIDENTIFICATION, delegate.getLinkIdentification() ) );
				}
				
				writeString( genXMLEndTag( GPSXMLTag.XML_TAG_OTHER ) );
			}
			
			writeString( genXMLEndTag( GPSXMLTag.XML_TAG_WAYPOINT ) ) ;
		}
	}
	
	//***************************************************************************
	//*
	//*     Delegated Interface Methods
	//*
	//***************************************************************************/

	public byte getType() 
	{
		return( delegate.getType() );
	}
	
	public byte getColour()
	{
		return( delegate.getColour() );
	}

	public byte getDisplayOptions()
	{
		return( delegate.getDisplayOptions() );
	}

	public byte getAttributes()
	{
		return( delegate.getAttributes() );
	}

	public short getSymbolType()
	{
		return( delegate.getSymbolType() );
	}

	public byte[] getSubclass()
	{
		return( delegate.getSubclass() );
	}

	public double getLatitude()
	{
		return( delegate.getLatitude() );
	}
	
	public double getLongitude()
	{
		return( delegate.getLongitude() );
	}

	public int getLatitudeSemicircles()
	{
		return( delegate.getLatitudeSemicircles() );
	}
	
	public int getLongitudeSemicircles()
	{
		return( delegate.getLongitudeSemicircles() );
	}

	public float getAltitude()
	{
		return( delegate.getAltitude() );
	}

	public float getDepth()
	{
		return( delegate.getDepth() );
	}

	public float getDistance()
	{
		return( delegate.getDistance() );
	}

	public String getStateCode()
	{
		return( delegate.getStateCode() );
	}
	
	public String getCountryCode()
	{
		return( delegate.getCountryCode() );
	}
	
	public int getEstimatedTimeEnroute()
	{
		return( delegate.getEstimatedTimeEnroute() );
	}

	public String getIdentification()
	{
		return( delegate.getIdentification() );
	}
	
	public String getComment()
	{
		return( delegate.getComment() );
	}
	
	public String getFacility()
	{
		return( delegate.getFacility() );
	}
	
	public String getCity()
	{
		return( delegate.getCity() );
	}
	
	public String getAddress()
	{
		return( delegate.getAddress() );
	}

	public String getCrossroad()
	{
		return( delegate.getCrossroad() );
	}
	
	public String getLinkIdentification()
	{
		return( delegate.getLinkIdentification() );
	}
}
